package com.midian.service.activity.impl;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.midian.common.dao.BaseDaoTemplet;
import com.midian.common.dao.OrderHelper;
import com.midian.common.dao.SearchHelper;
import com.midian.common.dao.SearchHelper.Type;
import com.midian.common.exception.BizException;
import com.midian.common.pager.Pager;
import com.midian.common.system.SysStatic;
import com.midian.model.activity.Activity;
import com.midian.model.activity.ActivityType;
import com.midian.service.common.BaseService;
import com.midian.service.activity.IActivityService;

/**
 * 活动业务实现类
 * @author Mengfh
 *
 */
@Service("activityService")
public class ActivityServiceImpl extends BaseService implements IActivityService {
	/**活动DAO*/
	private BaseDaoTemplet<Activity> activityDAO;
	
	@Resource(name = "activityDAO")
	public void setActivityDAO(BaseDaoTemplet<Activity> activityDAO) {
		this.activityDAO = activityDAO;
	}

	@Override
	public Activity add(Activity target) throws BizException {
		this.activityDAO.add(target);
		return target;
	}

	@Override
	public void update(Activity target) throws BizException {
		this.activityDAO.updateByConvertHql(target);
	}

	@Override
	public void delete(Serializable id) throws BizException {
		this.activityDAO.delete(id);
	}

	@Override
	public void delete(Serializable[] ids) throws BizException {
		this.activityDAO.delete(ids);
	}

	@Override
	public Activity get(Serializable id) throws BizException {
		return this.activityDAO.get(id);
	}

	@Override
	public List<Activity> showList(Activity target, Pager pager, List<OrderHelper> helper) throws BizException {
		return this.activityDAO.find(target, getSearchHelper(), helper, pager);
	}

	@Override
	public void opDelFlag(Serializable[] ids, Integer status) throws BizException {
		this.activityDAO.opDelFlag(ids, status);
	}

	@Override
	protected List<SearchHelper> getSearchHelper() {
		String[] attrs = {"organization","activityType","coverPic","title","organization.id","delFlag"};
		Type[] types = {Type.LEFTFETCH,Type.LEFTFETCH,Type.LEFTFETCH,Type.LIKE,Type.EQ,Type.EQ};
		return SearchHelper.getSearchList(attrs, types);
	}

	@Override
	public List<Activity> getActivitys() throws BizException {
		String hql = "from Activity a where a.delFlag = ?";
		return this.activityDAO.find(hql,new Object[]{SysStatic.NORMALDELFLAG});
	}

	
	
}
